#include "mushroom.h"
#define MUSHROOM_SPEED 0.1f;

CMushroom::CMushroom() : CMovable()
{
	life = 0;
}

CMushroom::~CMushroom()
{

}

void CMushroom::Activate(int Type,int World,float X, float Y)
{
	reality = 11;
	life = 1;
	type = Type;
	v_x = 0;
	v_y = -0.04f;
	movingWay = 1;
	startY = Y;
	pos_x = X;
	pos_y = Y-8;
	width = 16;
	height = 16;
	world = World;
}

void CMushroom::Update(int t)
{
	pos_x += v_x*t;
	pos_y += v_y*t;
	if(v_x != 0) CheckCol();
	if(startY - pos_y >= height && v_x == 0) 
	{
		v_y = 0;
		if(type != 0)	v_x = MUSHROOM_SPEED;
	}
}

void CMushroom::RenderFrame(LPDIRECT3DDEVICE9 d3ddv, int t)
{
	DWORD now = GetTickCount();
	Update(t);
	if (now - last_time > 200)
	{
		anim=(anim+1) % 2;
		last_time = now;
	}
	SpriteHandlerIP->Begin(D3DXSPRITE_ALPHABLEND);
	if(type == 0) // flower
		ItemPic->Render(_BackBuffer,pos_x,pos_y,0,world+anim);
	else if(type == 2) // green mushroom
		ItemPic->Render(_BackBuffer,pos_x,pos_y,1,2);
	else if(type == 1) // red mushroom
		ItemPic->Render(_BackBuffer,pos_x,pos_y,1,0);
	SpriteHandlerIP->End();
}

void CMushroom::Touch(CObjects* obj)
{
	obj->lvUp();
	life = 0;
}